package entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Francis
 */
@Entity
@Table(name = "book_type")
@NamedQueries({@NamedQuery(name = "Book.findAll", query = "SELECT b FROM Book b"), @NamedQuery(name = "Book.findByBookID", query = "SELECT b FROM Book b WHERE b.bookID = :bookID"), @NamedQuery(name = "Book.findByPersonID", query = "SELECT b FROM Book b WHERE b.personID = :personID"), @NamedQuery(name = "Book.findByName", query = "SELECT b FROM Book b WHERE b.name = :name"), @NamedQuery(name = "Book.findByCategory", query = "SELECT b FROM Book b WHERE b.category = :category"), @NamedQuery(name = "Book.findByDescription", query = "SELECT b FROM Book b WHERE b.description = :description"), @NamedQuery(name = "Book.findByPrice", query = "SELECT b FROM Book b WHERE b.price = :price"), @NamedQuery(name = "Book.findByQuantity", query = "SELECT b FROM Book b WHERE b.quantity = :quantity"), @NamedQuery(name = "Book.findByStatusCode", query = "SELECT b FROM Book b WHERE b.statusCode = :statusCode"), @NamedQuery(name = "Book.findByImage1", query = "SELECT b FROM Book b WHERE b.image1 = :image1"), @NamedQuery(name = "Book.findByImage2", query = "SELECT b FROM Book b WHERE b.image2 = :image2"), @NamedQuery(name = "Book.findByImage3", query = "SELECT b FROM Book b WHERE b.image3 = :image3"), @NamedQuery(name = "Book.findByTag1", query = "SELECT b FROM Book b WHERE b.tag1 = :tag1"), @NamedQuery(name = "Book.findByTag2", query = "SELECT b FROM Book b WHERE b.tag2 = :tag2"), @NamedQuery(name = "Book.findByTag3", query = "SELECT b FROM Book b WHERE b.tag3 = :tag3"), @NamedQuery(name = "Book.findByTag4", query = "SELECT b FROM Book b WHERE b.tag4 = :tag4"), @NamedQuery(name = "Book.findByTag5", query = "SELECT b FROM Book b WHERE b.tag5 = :tag5"), @NamedQuery(name = "Book.findByLocation", query = "SELECT b FROM Book b WHERE b.location = :location"), @NamedQuery(name = "Book.findByCondition", query = "SELECT b FROM Book b WHERE b.condition = :condition"), @NamedQuery(name = "Book.findByClicks", query = "SELECT b FROM Book b WHERE b.clicks = :clicks"), @NamedQuery(name = "Book.findByMinRating", query = "SELECT b FROM Book b WHERE b.minRating = :minRating"), @NamedQuery(name = "Book.findByAddDate", query = "SELECT b FROM Book b WHERE b.addDate = :addDate"), @NamedQuery(name = "Book.findByAddIP", query = "SELECT b FROM Book b WHERE b.addIP = :addIP"), @NamedQuery(name = "Book.findByIsGroupBuyItem", query = "SELECT b FROM Book b WHERE b.isGroupBuyItem = :isGroupBuyItem"), @NamedQuery(name = "Book.findByIsBuyNowItem", query = "SELECT b FROM Book b WHERE b.isBuyNowItem = :isBuyNowItem"), @NamedQuery(name = "Book.findByIsAdvItem", query = "SELECT b FROM Book b WHERE b.isAdvItem = :isAdvItem") //new queries
    , @NamedQuery(name = "Book.IncrementClicksByBookID", query = "UPDATE Book SET clicks = clicks+1 WHERE bookID = :bookID"), @NamedQuery(name = "Book.findByTag", query = "SELECT b FROM Book b WHERE b.tag1 = :tag OR b.tag2 = :tag OR b.tag3 = :tag OR b.tag4 = :tag OR b.tag5 = :tag")
})
public class Book implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "bookID", nullable = false)
    private Integer bookID;
    @Basic(optional = false)
    @Column(name = "personID", nullable = false)
    private int personID;
    @Basic(optional = false)
    @Column(name = "name", nullable = false)
    private String name;
    @Basic(optional = false)
    @Column(name = "category", nullable = false)
    private int category;
    @Column(name = "description")
    private String description;
    @Basic(optional = false)
    @Column(name = "price", nullable = false, precision = 19, scale = 4)
    private BigDecimal price;
    @Basic(optional = false)
    @Column(name = "quantity", nullable = false)
    private int quantity;
    @Basic(optional = false)
    @Column(name = "statusCode", nullable = false)
    private int statusCode;
    @Column(name = "image1", length = 200)
    private String image1;
    @Column(name = "image2", length = 200)
    private String image2;
    @Column(name = "image3", length = 200)
    private String image3;
    @Basic(optional = false)
    @Column(name = "tag1", nullable = false)
    private String tag1;
    @Column(name = "tag2")
    private String tag2;
    @Column(name = "tag3")
    private String tag3;
    @Column(name = "tag4")
    private String tag4;
    @Column(name = "tag5")
    private String tag5;
    @Column(name = "location")
    private String location;
    @Basic(optional = false)
    @Column(name = "condition", nullable = false)
    private int condition;
    @Basic(optional = false)
    @Column(name = "clicks", nullable = false)
    private int clicks;
    @Basic(optional = false)
    @Column(name = "minRating", nullable = false)
    private int minRating;
    @Basic(optional = false)
    @Column(name = "addDate", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date addDate;
    @Basic(optional = false)
    @Column(name = "addIP", nullable = false)
    private String addIP;
    @Basic(optional = false)
    @Column(name = "isGroupBuyItem", nullable = false)
    private boolean isGroupBuyItem;
    @Basic(optional = false)
    @Column(name = "isBuyNowItem", nullable = false)
    private boolean isBuyNowItem;
    @Basic(optional = false)
    @Column(name = "isAdvItem", nullable = false)
    private boolean isAdvItem;
    @Column(name = "activePeriod", nullable = false)
    private int activePeriod;
    @Column(name = "endDate", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date endDate;
    @Column(name = "meet")
    private boolean meet;
    @Column(name = "mail1")
    private boolean mail1;
    @Column(name = "mail2")
    private boolean mail2;
    @Column(name = "otherTradingMethod")
    private boolean otherTradingMethod;
    @Column(name = "otherTradingMethodDetail")
    private String otherTradingMethodDetail;
    @Column(name = "cash")
    private boolean cash;
    @Column(name = "ebank")
    private boolean ebank;
    @Column(name = "credit")
    private boolean credit;
    @Column(name = "cheque")
    private boolean cheque;
    @Column(name = "paypal")
    private boolean paypal;
    @Column(name = "otherPayingMethod")
    private boolean otherPayingMethod;
    @Column(name = "otherPayingMethodDetail")
    private String otherPayingMethodDetail;
    @Column(name = "postalFee1", precision = 19, scale = 4)
    private BigDecimal postalFee1;
    @Column(name = "postalFee2", precision = 19, scale = 4)
    private BigDecimal postalFee2;
    
    //customize properties
    @ManyToOne
    @JoinColumn(name = "personID", insertable=false, updatable=false)
    private Person person;
    //customize properties

    public Book() {
    }

    public Book(Integer bookID) {
        this.bookID = bookID;
    }

    public Book(Integer bookID, int personID, String name, int category, BigDecimal price, int quantity, int statusCode, String tag1, int condition, int clicks, int minRating, Date addDate, String addIP, boolean isGroupBuyItem, boolean isBuyNowItem, boolean isAdvItem) {
        this.bookID = bookID;
        this.personID = personID;
        this.name = name;
        this.category = category;
        this.price = price;
        this.quantity = quantity;
        this.statusCode = statusCode;
        this.tag1 = tag1;
        this.condition = condition;
        this.clicks = clicks;
        this.minRating = minRating;
        this.addDate = addDate;
        this.addIP = addIP;
        this.isGroupBuyItem = isGroupBuyItem;
        this.isBuyNowItem = isBuyNowItem;
        this.isAdvItem = isAdvItem;
    }

    public Integer getBookID() {
        return bookID;
    }

    public void setBookID(Integer bookID) {
        this.bookID = bookID;
    }

    public int getPersonID() {
        return personID;
    }

    public void setPersonID(int personID) {
        this.personID = personID;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getCategory() {
        return category;
    }

    public void setCategory(int category) {
        this.category = category;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public int getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(int statusCode) {
        this.statusCode = statusCode;
    }

    public String getImage1() {
        return image1;
    }

    public void setImage1(String image1) {
        this.image1 = image1;
    }

    public String getImage2() {
        return image2;
    }

    public void setImage2(String image2) {
        this.image2 = image2;
    }

    public String getImage3() {
        return image3;
    }

    public void setImage3(String image3) {
        this.image3 = image3;
    }

    public String getTag1() {
        return tag1;
    }

    public void setTag1(String tag1) {
        this.tag1 = tag1;
    }

    public String getTag2() {
        return tag2;
    }

    public void setTag2(String tag2) {
        this.tag2 = tag2;
    }

    public String getTag3() {
        return tag3;
    }

    public void setTag3(String tag3) {
        this.tag3 = tag3;
    }

    public String getTag4() {
        return tag4;
    }

    public void setTag4(String tag4) {
        this.tag4 = tag4;
    }

    public String getTag5() {
        return tag5;
    }

    public void setTag5(String tag5) {
        this.tag5 = tag5;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public int getCondition() {
        return condition;
    }

    public void setCondition(int condition) {
        this.condition = condition;
    }

    public int getClicks() {
        return clicks;
    }

    public void setClicks(int clicks) {
        this.clicks = clicks;
    }

    public int getMinRating() {
        return minRating;
    }

    public void setMinRating(int minRating) {
        this.minRating = minRating;
    }

    public Date getAddDate() {
        return addDate;
    }

    public void setAddDate(Date addDate) {
        this.addDate = addDate;
    }

    public String getAddIP() {
        return addIP;
    }

    public void setAddIP(String addIP) {
        this.addIP = addIP;
    }

    public boolean getIsGroupBuyItem() {
        return isGroupBuyItem;
    }

    public void setIsGroupBuyItem(boolean isGroupBuyItem) {
        this.isGroupBuyItem = isGroupBuyItem;
    }

    public boolean getIsBuyNowItem() {
        return isBuyNowItem;
    }

    public void setIsBuyNowItem(boolean isBuyNowItem) {
        this.isBuyNowItem = isBuyNowItem;
    }

    public boolean getIsAdvItem() {
        return isAdvItem;
    }

    public void setIsAdvItem(boolean isAdvItem) {
        this.isAdvItem = isAdvItem;
    }

    public int getActivePeriod() {
        return activePeriod;
    }

    public void setActivePeriod(int activePeriod) {
        this.activePeriod = activePeriod;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }
    public boolean getMeet() {
        return meet;
    }
    public void setMeet(boolean meet) {
        this.meet = meet;
    }
    public boolean getMail1() {
        return mail1;
    }
    public void setMail1(boolean mail1) {
        this.mail1 = mail1;
    }
    public boolean getMail2() {
        return mail2;
    }
    public void setMail2(boolean mail2) {
        this.mail2 = mail2;
    }
    public boolean getOtherTradingMethod() {
        return otherTradingMethod;
    }
    public void setOtherTradingMethod(boolean otherTradingMethod) {
        this.otherTradingMethod = otherTradingMethod;
    }
    public String getOtherTradingMethodDetail() {
        return otherTradingMethodDetail;
    }

    public void setOtherTradingMethodDetail(String otherTradingMethodDetail) {
        this.otherTradingMethodDetail = otherTradingMethodDetail;
    }
    public boolean getCash() {
        return cash;
    }
    public void setCash(boolean cash) {
        this.cash = cash;
    }
    public boolean getEbank() {
        return ebank;
    }
    public void setEbank(boolean ebank) {
        this.ebank = ebank;
    }
    public boolean getCredit() {
        return credit;
    }
    public void setCredit(boolean credit) {
        this.credit = credit;
    }
    public boolean getCheque() {
        return cheque;
    }
    public void setCheque(boolean cheque) {
        this.cheque = cheque;
    }
    public boolean getPaypal() {
        return paypal;
    }
    public void setPaypal(boolean paypal) {
        this.paypal = paypal;
    }
    public boolean getOtherPayingMethod() {
        return otherPayingMethod;
    }
    public void setOtherPayingMethod(boolean otherPayingMethod) {
        this.otherPayingMethod = otherPayingMethod;
    }
    public String getOtherPayingMethodDetail() {
        return otherPayingMethodDetail;
    }

    public void setOtherPayingMethodDetail(String otherPayingMethodDetail) {
        this.otherPayingMethodDetail = otherPayingMethodDetail;
    }

    public BigDecimal getPostalFee1() {
        return postalFee1;
    }

    public void setPostalFee1(BigDecimal postalFee1) {
        this.postalFee1 = postalFee1;
    }
    public BigDecimal getPostalFee2() {
        return postalFee2;
    }

    public void setPostalFee2(BigDecimal postalFee2) {
        this.postalFee2 = postalFee2;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (bookID != null ? bookID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Book)) {
            return false;
        }
        Book other = (Book) object;
        if ((this.bookID == null && other.bookID != null) || (this.bookID != null && !this.bookID.equals(other.bookID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Book[bookID=" + bookID + "]";
    }

    //customize properties
    public Person getPerson() {
        return person;
    }
}
